package com.rabbitmq.provider.controller;

import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageBuilder;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.nio.charset.Charset;

/**
 * @作者: 林江
 * @创建时间: 2023/11/14
 * @功能: 不同种发送消息的方式
 */
@RestController
public class RabbitmqProviderController {

    @Autowired
    RabbitTemplate rabbitTemplate;

    @RequestMapping("/test01")
    public String test01() {
        String data = "你长得还可以哦。。。。。";
        Message message = MessageBuilder
                .withBody(data.getBytes(Charset.defaultCharset()))
                .build();
        // 第一种
        rabbitTemplate.send("sms", "", message);
        return "succuss";
    }


    @RequestMapping("/test02")
    public String test02() {
        String data = "你长得还可以哦。。。。。";
        Message message = MessageBuilder
                .withBody(data.getBytes(Charset.defaultCharset()))
                .build();
        rabbitTemplate.convertAndSend("sms1","",message);
        return "succuss";
    }
}
